package com.raos.zkconfig.handwritten.controller;

import com.raos.zkconfig.handwritten.refresh.RaosRefreshScope;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 手写 ZK 配置中心之 自定义zk配置中心 演示controller案例
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2022/9/5 22:35
 */
@RestController
@RequestMapping("/product")
@RaosRefreshScope
public class ProductController {

    @Resource
    private Environment environment;

    @RequestMapping("/remote-config-env")
    public String remoteConfig() {
        return "[env] id: " + this.environment.getProperty("id")
                + ", product: " + this.environment.getProperty("product")
                + ", price: " + this.environment.getProperty("price");
    }

    @Value("${id}")    // 字段的值什么时候赋值的
    private String id;

    @Value("${product}")
    private String product;

    @Value("${price}")
    private String price;

    @RequestMapping("/remote-config-value")
    public String remoteConfigValue() {
        return "[@Value] id: " + this.id
                + ", product: " + this.product
                + ", price: " + this.price;
    }

}